home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Hardware / BlizKick / Modules / hackdisk.ASM < prev    next >
Encoding:
Assembly Source File  |  2002-03-13  |  6.1 KB  |  286 lines

  1. ; FILE: Source:modules/hackdisk.ASM          REV: 26 --- Install hackdisk.device
  2.  
  3. ;
  4. ; Plant hackdisk.device -Module
  5. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6. ; This patch module will plant hackdisk.device into current ROM image, so
  7. ; replacing trackdisk.device.
  8. ;
  9. ; Device will be loaded from file "devs:hackdisk.device".
  10. ;
  11. ; hackdisk.device is copyright © 1992,93 by Dan Babcock.
  12. ; Version 2.04 is copyright © 1996-1997 by Harry Sintonen. =o)
  13. ;
  14. ; Actually, version 2.04 of hackdisk.device was "made" (haha!) by me
  15. ; to be compatible with BlizKick. Version 2.02 had a bug which caused
  16. ; it to fail when used with this module (it tried to open
  17. ; intuition.library before it was even initialized. I had to modify it,
  18. ; because changing trackdisk.device's residenttag priority would have
  19. ; been too hackish. Trackdisk (and hackdisk!) has priority 20 and
  20. ; intuition has 10).
  21. ;
  22. ; This module has been tested with version 2.04.
  23. ;
  24. ; 1.2: Made it possible to patch trackdisk.device that is inside
  25. ;      extresbuf.
  26. ;
  27. ; Written by Harry Sintonen.
  28. ; This source code is Public Domain.
  29. ;
  30.  
  31.     incdir    "include:"        ; Some required...
  32.     include    "exec/types.i"
  33.     include    "exec/libraries.i"
  34.     include    "blizkickmodule.i"
  35.  
  36. _LVOAllocMem    EQU    -$C6
  37. _LVOFreeMem    EQU    -$CC
  38. _LVOCopyMem    EQU    -$270
  39.  
  40. _LVOOpen    EQU    -$1E
  41. _LVOClose    EQU    -$24
  42. _LVORead    EQU    -$2A
  43. _LVOSeek    EQU    -$42
  44. _LVOInternalLoadSeg    EQU    -$2F4        ; 2.0+
  45. _LVOInternalUnLoadSeg    EQU    -$2FA
  46.  
  47. MODE_OLDFILE    EQU    1005
  48. OFFSET_CURRENT    EQU    0
  49. HUNK_RELOC32    EQU    1004
  50.  
  51. call    MACRO
  52.     jsr    (_LVO\1,a6)
  53.     ENDM
  54.  
  55.     SECTION    PATCH,CODE
  56. _DUMMY_LABEL
  57.     BK_PTC
  58.  
  59. ; Code is run with following incoming parameters:
  60. ;
  61. ; a0=ptr to ROM start (buffer)    eg. $1DE087B8
  62. ; a1=ptr to ROM start (ROM)    eg. $00F80000 (do *not* access!)
  63. ; d0=ROM lenght in bytes    eg. $00080000
  64. ; a2=ptr to _FindResident routine (will search ROM buffer for resident tag):
  65. ;    CALL: jsr (a2)
  66. ;      IN: a0=ptr to ROM, d0=rom len, a1=ptr to resident name
  67. ;     OUT: d0=ptr to resident (buf) or NULL
  68. ; a3=ptr to _InstallModule routine (can be used to plant a "module"):
  69. ;    CALL: jsr (a3)
  70. ;      IN: a0=ptr to ROM, d0=rom len, a1=ptr to module, d6=dosbase
  71. ;     OUT: d0=success
  72. ; a4=ptr to _Printf routine (will dump some silly things (errormsg?) to stdout ;-)
  73. ;    CALL: jsr (a4)
  74. ;      IN: a0=FmtString, a1=Array (may be 0), d6=dosbase
  75. ;     OUT: -
  76. ; d6=dosbase, a6=execbase
  77. ;
  78. ; Code should return:
  79. ;
  80. ; d0=true if succeeded, false if failed.
  81. ; d1-d7/a0-a6 can be trashed. a7 *must* be preserved! ;-)
  82.  
  83.  
  84. ; NOTE: Kickstart *is* 2.0+
  85.  
  86.     cmp.w    #33,($C,a0)        ; Requires KS ROM V1.2+
  87.     bhs.b    .go
  88.     moveq    #0,d0
  89.     rts
  90.  
  91. .go
  92.     lea    (regs,pc),a5
  93.     movem.l    d0/a0-a1,(a5)
  94.  
  95.     moveq    #0,d7
  96.  
  97.     lea    (_tdname,pc),a1        ; _FindResident
  98.     jsr    (a2)
  99.     tst.l    d0
  100.     beq    .xit
  101.     move.l    d0,a5            ; a5=trackdisk resident
  102.  
  103.     moveq    #1,d7
  104.     move.l    (RT_IDSTRING,a5),d0
  105.     beq    .xit
  106.     bsr    buffer
  107.     move.l    d0,a0
  108.     lea    (_hdiname,pc),a1    ; NOTE: lowercase!
  109.     moveq    #8-1,d1            ; 'hackdisk'
  110. .cmp    move.b    (a0)+,d0
  111.     or.b    #32,d0            ; lowercase
  112.     cmp.b    (a1)+,d0
  113.     dbne    d1,.cmp
  114.     tst.w    d1            ; Test if already installed
  115.     bmi    .xit
  116.  
  117.     moveq    #0,d7
  118.     exg    d6,a6
  119.     lea    (_hddname,pc),a0
  120.     move.l    a0,d1
  121.     move.l    #MODE_OLDFILE,d2
  122.     call    Open
  123.     move.l    d0,d4
  124.     beq    .exit
  125.  
  126.     ; d0 = fh
  127.     sub.l    a0,a0
  128.     lea    (funcs,pc),a1
  129.     subq.l    #4,sp
  130.     move.l    sp,a2
  131.     call    InternalLoadSeg
  132.     addq.l    #4,sp
  133.     move.l    d0,d5
  134.     beq    .close
  135.     bmi    .baddie
  136.  
  137.     move.l    d5,a2
  138.     add.l    a2,a2
  139.     add.l    a2,a2            ; aptr 1st hunk
  140.     tst.l    (a2)+            ; Requires single hunk exe!
  141.     bne    .baddie            ; a2=hunk start
  142.  
  143.     move.l    (RT_ENDSKIP,a5),d0
  144.     bsr    buffer
  145.     move.l    d0,d2            ; d2 = rt_endskip in buffer
  146.     move.l    (RT_ENDSKIP,a2),d1
  147.     sub.l    a2,d1            ; d1=hd res size
  148.     sub.l    a5,d2            ; d2=td res size
  149.     cmp.l    d2,d1
  150.     bhi    .baddie            ; if hd>td fail!
  151.  
  152. BUFSIZE    EQU    512
  153.     lea    (-BUFSIZE,sp),sp
  154. .scan    move.l    d4,d1            ; Scan backwards for HUNK_RELOC32:
  155.     moveq    #-8,d2            ; This is *really* heavy magic...
  156.     moveq    #OFFSET_CURRENT,d3
  157.     call    Seek
  158.     tst.l    d0
  159.     bmi.b    .baddie2
  160.     move.l    d4,d1
  161.     move.l    sp,d2
  162.     moveq    #4,d3
  163.     call    Read
  164.     cmp.l    d0,d3
  165.     bne.b    .baddie2
  166.     cmp.l    #HUNK_RELOC32,(sp)
  167.     bne.b    .scan
  168.  
  169.     move.l    d4,d1            ; Read reloc table
  170.     move.l    sp,d2
  171.     move.l    #BUFSIZE,d3
  172.     call    Read
  173.     tst.l    d0
  174.     bmi.b    .baddie2
  175.  
  176.     move.l    sp,a0
  177.     move.l    (a0)+,d3        ; d3=number of relocs
  178.     tst.l    (a0)+            ; Must be hunk0 relocs!
  179.     bne.b    .scan
  180.     move.l    d3,d1
  181.     lsl.l    #2,d1
  182.     tst.l    (a0,d1.l)        ; Must be only relocs!
  183.     bne.b    .scan
  184.  
  185.     move.l    (RT_ENDSKIP,a2),d0
  186.     sub.l    a2,d0
  187.     move.l    d0,-(sp)        ; (sp)=hd res size
  188.  
  189.     move.l    a5,d0
  190.     bsr    romaddress
  191.     sub.l    a2,d0
  192.  
  193. .subl    move.l    (a0)+,d2        ; ReRelocate :)
  194.     add.l    d0,(a2,d2.l)
  195.     subq.l    #1,d3
  196.     bne.b    .subl
  197.  
  198.     move.l    a2,a0            ; Copy it!
  199.     move.l    a5,a1
  200.     move.b    (RT_VERSION,a1),(RT_VERSION,a0)
  201.     move.b    (RT_PRI,a1),(RT_PRI,a0)
  202.     move.l    (sp)+,d0        ; d0=hd res size
  203.     exg    d6,a6
  204.     call    CopyMem
  205.     exg    d6,a6
  206.  
  207. ; As a side remark: This "loadseg-scanbackforrelocs-rerelocate-copy" 
  208. ; -code worked at first try! Honestly I didn't think it would... ;)
  209.  
  210.     moveq    #1,d7            ; Succeed!
  211.  
  212. .baddie2    lea    (BUFSIZE,sp),sp
  213.  
  214. .baddie    lea    (freefunc,pc),a1
  215.     move.l    d5,d1
  216.     call    InternalUnLoadSeg
  217.  
  218. .close    move.l    d4,d1
  219.     call    Close
  220.  
  221. .exit    exg    d6,a6
  222.     move.l    d7,d0            ; Valid counter?
  223.     bne.b    .xit
  224.     lea    (_error1,pc),a0        ; a0=fmt
  225.     pea    (_hddname,pc)
  226. .fail    move.l    sp,a1            ; a1=array
  227.     jsr    (a4)            ; Call _Printf
  228.     addq.l    #4,sp
  229.     moveq    #0,d0            ; Return fail
  230. .xit    rts
  231.  
  232. .perr    lea    (_error2,pc),a0
  233.     pea    (_hdiname,pc)
  234.     bra.b    .fail    
  235.  
  236.  
  237. funcs    dc.l    readfunc
  238.     dc.l    allocfunc
  239.     dc.l    freefunc
  240.  
  241. readfunc    jmp    (_LVORead,a6)
  242. allocfunc    jmp    (_LVOAllocMem,a6)
  243. freefunc    jmp    (_LVOFreeMem,a6)
  244.  
  245.  
  246. buffer    ;test if inside rom bounds?
  247.     move.l    (rom_log,pc),d1
  248.     cmp.l    d1,d0
  249.     blo.b    .nofix
  250.     add.l    (rom_size,pc),d1
  251.     cmp.l    d1,d0
  252.     bhs.b    .nofix
  253.     ; inside rom, so generate ram buffer address
  254.     sub.l    (rom_log,pc),d0        -$f80000
  255.     add.l    (rom_phys,pc),d0    +buffer
  256. .nofix    rts
  257.  
  258. romaddress    ;test if inside rom buffer bounds?
  259.     move.l    (rom_phys,pc),d1
  260.     cmp.l    d1,d0
  261.     blo.b    .nofix
  262.     add.l    (rom_size,pc),d1
  263.     cmp.l    d1,d0
  264.     bhs.b    .nofix
  265.     ; inside rom, so generate ram buffer address
  266.     sub.l    (rom_phys,pc),d0    -buffer
  267.     add.l    (rom_log,pc),d0        +$f80000
  268. .nofix    rts
  269.  
  270. _tdname    dc.b    'trackdisk.device',0
  271. _hdiname    EQU    *+5
  272. _hddname    dc.b    'devs:hackdisk.device',0
  273.  
  274. _error1    dc.b    'Couldn''t load "%s"!',10,0
  275. _error2    dc.b    'Couldn''t utilize this %s version!',10,0
  276.  
  277.     CNOP    0,2
  278. regs
  279. rom_size    ds.l    1
  280. rom_phys    ds.l    1
  281. rom_log    ds.l    1
  282.  
  283.     SECTION    VERSION,DATA
  284.  
  285.     dc.b    '$VER: hackdisk_PATCH 1.2 (13.12.00)',0
  286.